//
//  PhotosBroadCastView.m
//  YouWoYou
//
//  Created by dlios on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "PhotosBroadCastView.h"
#import "PhotosCollectionViewCell.h"


@interface PhotosBroadCastView () <UICollectionViewDataSource, UICollectionViewDelegate>


@end

@implementation PhotosBroadCastView

static NSString * const reuseIdentifier = @"Cell";

- (void)dealloc
{
    
    [_photoArr release];
    [_collection release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        // 设置图片轮播去的cell
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        
        flowLayout.itemSize = CGSizeMake(self.frame.size.width, self.frame.size.height);
//        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
   
        
        self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:flowLayout];
//        self.collection.backgroundColor = [UIColor blackColor];
        
        self.collection.delegate = self;
        self.collection.dataSource = self;
        [self.collection setPagingEnabled:YES];
        
        [self.collection registerClass:[PhotosCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
        [self addSubview:self.collection];
        
        [_collection release];

        [flowLayout release];
        
    }
    return self;
}

#pragma mark collection的必备的两个方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1000;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotosCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    cell.slide = [self.photoArr objectAtIndex:(indexPath.item % 3)];
  
    return cell;
}

- (void)addtimer {
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(time) userInfo:nil repeats:YES];
    // 循环播放
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

- (void)time
{
    self.collection.contentOffset = CGPointMake(self.collection.frame.origin.x + self.frame.size.width, 0);
}







/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
